<template>
  <div class="content">
    <el-form ref="form" :model="form" label-width="80px" :inline="true">
<!--      <el-button-->
<!--        type="primary"-->
<!--        size="mini"-->
<!--        class="btn"-->
<!--        style="margin-right: 10px"-->
<!--        @click="editAddOrUpdate(1)"-->
<!--      >-->
<!--        <i class="fa fa-plus" style="margin-right:5px;"></i>新增-->
<!--      </el-button>-->
    </el-form>

    <!-- <el-divider></el-divider> -->

    <template>
      <el-table
        :data="tableData"
        v-loading="loading"
        size="mini"
        height="470"
        style="width: 100%"
      >

        <el-table-column prop="id" width="150" label="编号"></el-table-column>

        <el-table-column prop="type" label="类别">
          <template slot-scope="scope">
             {{scope.row.type==1?'学生':'老师'}}
          </template>
        </el-table-column>

        <el-table-column prop="limitCount" label="刷脸次数（次）"></el-table-column>

        <el-table-column prop="limitAmt" label="单次限制金额（元）"></el-table-column>

        <el-table-column prop="limitTime" label="刷脸间隔（秒）"></el-table-column>

        <el-table-column fixed="right" :label="$t('action.operation')" width="250">
          <template slot-scope="scope">
            <el-button size="mini" @click="editAddOrUpdate(2,scope.row.id)">
              <i class="fa fa-edit" style="margin-right:5px;"></i>
              {{$t('action.edit')}}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[10, 15, 20,50,100]"
      :page-size="everyPageNum"
      layout="total, sizes,prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
    <!--新增编辑弹框-->
    <el-dialog center="true" :title="updateStatus==1?'创建配置':'编辑配置'" :visible.sync="showEdit" width="50%" v-dialogDrag>
      <edit @hideEdit="hideEditStatus" ref="child" :msg="updateStatus"></edit>
    </el-dialog>
  </div>
</template>

<script>
import Cookies from "js-cookie";
import edit from "@/components/PayConfigManagement/edit";

export default {
  name: "editCanteen",
  components: {
    edit
  },
  data() {
    return {
      url: this.$Config.url,
      showEdit: false, //显示编辑弹框
      updateStatus: 1, //默认是新增
      total: 1, //总页数
      loading: false,
      everyPageNum: 10, //每页多少条
      currentPage: 1, //当前页
      tableData: []
    };
  },
  mounted() {
    this.common();
  },
  methods: {
    hideEditStatus(status) {
      this.showEdit = false;
      this.common(this.currentPage, this.everyPageNum);
    },
    editAddOrUpdate(status, id) {
      this.showEdit = true;
      if (status == 1) {
        //新增
        this.updateStatus = 1;
        setTimeout(() => {
          this.$refs["child"].resetForm("form");
        }, 0);
      } else {
        //编辑
        this.updateStatus = 2;
        setTimeout(() => {
          this.$refs["child"].resetData(id);
        }, 0);
      }
    },
    handleSizeChange(val) {
      //   每页多少条
      this.everyPageNum = val;
      this.common(this.currentPage, val);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.common(val, this.everyPageNum);
    },
    common(pageNo = 1, pageSize = 10) {
      const that = this;
      that.loading = true;
      this.$axios
        .get(that.url + "/admin/payConfig/page", {
          params: {
            pageNo,
            pageSize,
          },
          headers: {
            "x-baie-admin-token": Cookies.get("token")
          }
        })
        .then(function(res) {
          that.loading = false;
          if (res.data.code == 200) {
            that.tableData = res.data.data.records;
            that.total = res.data.data.total;
          } else {
            that.$message({
              message: res.data.msg,
              type: "warning"
            });
          }
        })
        .catch(function(error) {
          that.loading = false;
          console.log(error);
        });
    },
    handleClick(row) {
      console.log(row);
    }
  }
};
</script>

<style scoped lang="scss">
.table_btn {
  background: #eee;
  color: #7b9dda;
  border: none;
  outline: none;
  padding: 4px 10px;
  margin-bottom: 5px;
  border-radius: 5px;
}

.button_list {
  margin-bottom: 10px;
}

.content {
  text-align: left;
}

.el-divider {
  margin: 10px 0;
}

.btn {
  margin-top: 7px;
}

.el-form-item {
  margin-bottom: 0;
}

.el-pagination {
  float: right;
  margin: 20px 10px;
}
</style>
